<template>
	<view class="home-layout page-bg">
		
		<custom-nav-bar title="推荐"></custom-nav-bar>
		<view class="banner">
			<swiper circular indicator-dots indicator-color="rgba(255,255,255,0.5)" indicator-active-color="#fff"
				autoplay interval="1000">
				<swiper-item v-for="(item,index) in bannerList" :key="item._id">
					<image :src="item.picurl" mode="aspectFill"></image>
				</swiper-item>

			</swiper>
		</view>

		<view class="notice">
			<view class="left">
				<uni-icons type="sound-filled" size="20" ></uni-icons>
				<text class="text">公告</text>
			</view>

			<view class="center">
				<swiper vertical autoplay interval="1500" :duration="300" circular>
					<swiper-item v-for="(item,index) in noticList" :key="item._id">
						<text class="text">{{item.title}}</text>
					</swiper-item>

				</swiper>
			</view>

			<view class="right">
				<uni-icons type="right" size="16" color="#333"></uni-icons>
			</view>
		</view>

		<view class="select">
		<common-title>
				<template #name>
					<view>每日推荐</view>
				</template>
				
				<template #custom>
					<view class="date">
						<uni-icons type="calendar" size="18" ></uni-icons>
						<view class="text">
								<uni-dateformat :date="Date.now()" format="dd日" ></uni-dateformat>
						</view>
					
					</view>
				</template> 
			</common-title> 
			<view class="context">
				<scroll-view scroll-x>
					<view class="box" v-for="item in dayRandom" :key="item._id" @click="goPreView">
						<image :src="item.smallPicurl" mode="aspectFill"></image>
					</view>
				</scroll-view>
			</view>
		</view>
		
		<view class="theme">
			<common-title>
				<template #name>
					专题精选
				</template>
				
				<template #custom>
					<navigator url="" class="more">More+</navigator>
				</template>
			</common-title>
			
			<view class="content">
				<theme-item v-for="item in 8"></theme-item>
				<theme-item :isMore="true"></theme-item>
			</view>
		</view>
	
	
	
	</view>
</template>

<script setup>
	import { ref } from 'vue';
	import { apiGetBanner ,apiGetDayRandom,apiGetNotice } from '@/api/apis.js';
	const bannerList = ref([])
	
	const dayRandom = ref([])
	
	const noticList = ref([])

async function getBannerList(){
const {data} = await apiGetBanner()
bannerList.value = data

}

getBannerList()

async function getDayRandom(){
	const {data} = await apiGetDayRandom()
	dayRandom.value = data
}

getDayRandom()


async function getNotice(){
	const {data} = await apiGetNotice({select:true})
	// console.log(res,'noticRes');
	noticList.value = data
}
getNotice()
// 跳转到预览页面
function goPreView(){
	uni.navigateTo({
		url:"/pages/preview/preview"
	})
}


</script>

<style lang="scss" scoped>
@import '@/common/style/base-style.scss';
	.home-layout {

		.banner {
			width: 750rpx;
			padding: 30rpx 0;

			swiper {
				width: 750rpx;
				height: 340rpx;

				&-item {
					padding: 0 30rpx;
					width: 100%;
					height: 100%;

					image {
						width: 100%;
						height: 100%;
						border-radius: 10rpx;
					}
				}
			}
		}

		.notice {
			display: flex;
			justify-content: space-between;
			align-items: center;
			height: 80rpx;
			width: 690rpx;
			background-color: #ccc;
			margin: 0 auto;
			border-radius: 80px;
			line-height: 80rpx;

			.left {
				display: flex;
				align-items: center;
				justify-content: center;
				width: 140rpx;
				
				:deep(){
					.uni-icons{
						color: $brand-theme-color !important;
					}
				}
			

				.text {
					font-weight: 600;
					color:  $brand-theme-color;
					font-size: 28rpx;
				}
			}

			.center {
				flex: 1;

				swiper {
					height: 80rpx;

					swiper-item {
						height: 100%;
						overflow: hidden;
						white-space: nowrap;
						/* 修改这里 */
						text-overflow: ellipsis;

						/* 添加这两行 */
						.text {
							height: 100%;
							font-size: 30rpx;
							color: #666;

						}
					}
				}
			}

			.right {
				width: 70rpx;
			}
		}


		.select {
			padding-top: 50rpx;
			
			.date{
				color: $brand-theme-color;
				display: flex;
				align-items: center;
				.text{
					margin-left: 5rpx;
				}
				:deep(){
					.uni-icons{
						color:$brand-theme-color;
					}
				}
			}

			.context {
				width: 720rpx;
				margin: 30rpx 0 0 30rpx;

				scroll-view {
					// height: 100%;
					white-space: nowrap;

					.box {
						display: inline-block;
						width: 200rpx;
						height: 430rpx;
						margin-right: 15rpx;
						image{
							width: 100%;
							height: 100%;
							border-radius: 10rpx;
						}
					}
					.box:last-child{
						margin-right: 30rpx;
					}
				}
			}
		}
		
		
		
		.theme{
			padding:  50rpx 0;
			.more{
				font-size: 32rpx;
				color: #888;
			}
			.content{
				display: grid;
				gap: 15rpx;
				grid-template-columns: repeat(3,1fr);
				margin-top: 30rpx;
				padding: 0 30rpx;
			}
		}
	}
</style>